<%-- 
    Document   : MDoctorList
    Created on : 26 ?.?. 2554, 13:08:38
    Author     : SUNTIPARB
--%>
<%@page import="java.util.ResourceBundle"%>
<%-- Form Function --%>
<script type="text/javascript">

<%ResourceBundle resource = ResourceBundle.getBundle("Constant_en");%>
    $(document).ready(function() {
        $("#formSearch").find("input, select").uniform();
        $("#btnReset").click(function(){
            $("#formSearch").get(0).reset();
            $.uniform.update(" input, select");
            return false});

        $("#formSearch").validate({
            submitHandler: function(form) {
                gridReload();
                //$(form).ajaxSubmit();
            }
        });
    });

</script>
<%-- End Form Function --%>

<%-- jQGrid Init  --%>
<script type="text/javascript">
jQuery.extend($.fn.fmatter , {
    editButtonFormatter : function editButtonFormatter(cellvalue, options, rowdata) {
    return "<a href=\"javascript:ContentAjaxRequest('SRV/MDoctorDetail?id=" + rowdata[0] + "', 'section #container')\" ><img src='<%=request.getContextPath()%>/images/document_edit.png' /></a> ";
}
});
jQuery.extend($.fn.fmatter , {
    deleteButtonFormatter : function deleteButtonFormatter(cellvalue, options, rowdata) {
    return "<a href='#grid' onclick='deleteRow("+rowdata[0]+")' ><img src='<%=request.getContextPath()%>/images/icon_delete.png' /></a> ";
}
});

</script>
<script type="text/javascript">

   $(function() {
        $("#grid").jqGrid({
            url:'<%=request.getContextPath()%>/SRV/MDoctorList/grd_search',
            datatype: 'json',
            mtype: 'POST',
            colNames:['Id','Name', 'Surname', 'Sex', 'Code', 'Edit', 'Delete'],
            colModel:[
                {name:'ID',index:'id', width:40},
                {name:'name',index:'name', width:150},
                {name:'surname',index:'surname', width:150},
                {name:'sex',index:'sex', width:55, sortable:false},
                {name:'code',index:'code', width:150},
                {name:'edit',index:'edit', align:'center', width:40, sortable:false,formatter:'editButtonFormatter'},
                {name:'delete',index:'delete', align:'center', width:40, sortable:false,formatter:'deleteButtonFormatter'}
       ],
            postData: {
            },
            rowNum:20,
            rowList:[20,40,60],
            height: 200,
            width: 940,
            rownumbers: true,
            pager: '#pager',
            sortname: 'id',
            viewrecords: true,
            sortorder: "asc",
            caption:"Doctor",
            emptyrecords: "<%= resource.getString("EmptyRecordGrid") %>",
            loadonce: false,
            loadComplete: function() {
                //alert("Complete");
            },
            jsonReader : {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: true, //if 'false' will chage json reader format to 'name' require
                //cell: "cell",
                id: "0" //id: "id"
            }
        });
        $("#grid").jqGrid('navGrid','#pager',
        {edit:false,add:false,del:false,search:false},
        {
            sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'],
            closeOnEscape: true,
            multipleSearch: true,
            closeAfterSearch: true }
        );
        
        $("#grid").navButtonAdd('#pager',
            {
                caption:"Add",
                buttonicon:"ui-icon-plus",
                onClickButton: function(){
                    ContentAjaxRequest('SRV/MDoctorDetail?id=-1', 'section #container');
                },
                position: "last",
                title:"Add New Doctor",
                cursor: "pointer"
            }
        );
    }
);
    //jQuery("#grid").setGridWidth(800, true)
</script>

<%-- End jQGrid Init --%>

<%-- jQGrid Search Function --%>
<script type="text/javascript">
    function gridReload(){
        var txtName = jQuery("#txtName").val();
        var txtSurname = jQuery("#txtSurname").val();
        var txtCode = jQuery("#txtCode").val();
        jQuery("#grid").jqGrid('setGridParam'
        ,{url:"<%=request.getContextPath()%>/SRV/MDoctorList/grd_search"
                +"?txtName="+txtName
                +"&txtSurname="+txtSurname
                +"&txtCode="+txtCode
            ,page:1}).trigger("reloadGrid");
    }
</script>
<%-- End jQGrid Search Function --%>

<%-- jQGrid Function --%>
<script type="text/javascript">
    function deleteRow(rowid) {
        $("#grid").jqGrid( 'delGridRow', rowid,
        {url: '<%=request.getContextPath()%>/SRV/MDoctorList/grd_delete'+'?id='+rowid,
            reloadAfterSubmit:true,
            beforeShowForm: function() {
                //change title
                $(".delmsg").replaceWith('<span style="white-space: pre;">' +
                    '<%= resource.getString("DeleteMessage") %>' + '</span>');
            }
        });
    }

</script>
<%-- End jQGrid Function --%>

<div class="grid_16">
    <!-- insert content here -->
    
            <form id="formSearch" class="form" action="" method="GET">
               <table class="bgTable">

            <tr >
                <td colspan="4" class="bgheader" ><h5>Search Doctor</h5></td>
            </tr>
            <tr >
                <td colspan="4" class="bgtop" >&nbsp;</td>
            </tr>
            <tr >
                <td  class="bgCellNormal"> Name ::&nbsp;</td>
              <td class="bgCellInput"><input type="text" name="txtName" id="txtName" class="" value="" /></td>
                <td  class="bgCellNormal">Surname ::&nbsp;</td>
              <td  class="bgCellInput"> <input type="text" name="txtSurname" id="txtSurname" class="" value="" /></td>
            </tr>
            <tr>
              <td class="bgCellNormal" >Code  ::&nbsp;</td>
              <td class="bgCellInput" >     <input type="text" name="txtCode" id="txtCode" class="" value="" /></td>
              <td class="bgCellNormal"  >&nbsp;</td>
              <td class="bgCellInput" >&nbsp;</td>
            </tr>
            <tr>
                <td class="bgCellNormal" >&nbsp;</td>
                <td class="bgCellInput" >&nbsp;</td>
                <td class="bgCellNormal"  >&nbsp;</td>
                <td class="bgCellInput" >&nbsp;</td>
            </tr>
            <tr>
                <td colspan="4"  class="bgbutton">
                    <input type="reset" name="btnReset" id="btnReset" value="Reset" /> &nbsp;&nbsp;
                  <input type="submit" name="btnSubmit" id="btnSubmit" value="Search" /> </td>
            </tr>
        </table>
             
            </form>
        
    <br />
    <div id="content-placeholder">
        <div id="jqgrid">
            <table id="grid"></table>
            <div id="pager"></div>
        </div>

        <div id="dialog" title="Feature not supported" style="display:none">
            <p>That feature is not supported.</p>
        </div>

        <div id="dialogSelectRow" title="Warning" style="display:none">
            <p>Please select row</p>
        </div>
    </div>
</div>

